//
//  UITableViewSecondCell.m
//  newload
//
//  Created by xue-iOS-work on 16/9/25.
//  Copyright © 2016年 xue. All rights reserved.
//

#import "UITableViewSecondCell.h"
#import "LFFreshOrderCollectionViewCell.h"
static NSString *collectionCell_id = @"collectionCell_id";

@interface UITableViewSecondCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *footNameLabel;
@property (weak, nonatomic) IBOutlet UIView *colorView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property(nonatomic,strong)NSArray *goodsArray;


@end
@implementation UITableViewSecondCell

-(void)setModels:(LFFreshOrderActRowModel *)models
{
    _models = models;
    // 食品名字
    self.footNameLabel.text = self.models.category_detail.name;
    // 食品颜色
    NSString *str = self.models.category_detail.category_color;
    self.footNameLabel.textColor = [UIColor colorWithHexString:str];
    self.colorView.backgroundColor = [UIColor colorWithHexString:str];
    // 获取全局的数组
    
    // 模型数组
    NSArray *modelArray = self.models.category_detail.goods;
    self.goodsArray = modelArray;
    [self.collectionView reloadData];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // 初始化UI
    [self setupUI];
    
}
#pragma mark - 初始化UI
-(void)setupUI{
    // 注册
    [self.collectionView registerNib:[UINib nibWithNibName:@"LFFreshOrderCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:collectionCell_id];

    // 设置数据源
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
}
#pragma mark - 数据源
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LFFreshOrderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCell_id forIndexPath:indexPath];
    LFFreshOrdergoodsModel *model = self.goodsArray[indexPath.row];
    cell.model = model;
    //判断价钱一样的话 隐藏原价
    if([model.market_price isEqualToString:model.partner_price]){
        cell.YuanPrice.alpha = 0;
    }else
    {
        cell.YuanPrice.alpha = 1;
    }
    //判断是否缺货
    if(model.number==0){
        cell.increateButton.alpha = 0;
        cell.buHuoLabel.alpha = 1;
    }else
    {
        cell.increateButton.alpha = 1;
        cell.buHuoLabel.alpha = 0;
    }
    return cell;
}

#pragma mark - collectionView代理
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.myBlock) {
        LFFreshOrdergoodsModel *model = self.goodsArray[indexPath.row];
        self.myBlock(model);
        
    }
    
}

@end
